package com.dragon.app.concurrent;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class DeadLock {

	public static void main(String[] args) {
		String lock1 = "lock1";
		String lock2 = "lock2";

		new Thread(() -> {
			synchronized (lock1) {
				try {
					TimeUnit.SECONDS.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (lock2) {
					System.out.println(Thread.currentThread().getName());
				}
			}
		}).start();

		new Thread(() -> {
			synchronized (lock2) {
				try {
					TimeUnit.SECONDS.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (lock1) {
					System.out.println(Thread.currentThread().getName());
				}
			}
		}).start();

	}

}
